﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DATA
    {
        private DateTime m_Created;
        private string m_Database;
        private string m_Path;
        private string m_Version;

        public DATA()
        {
            this.m_Database = "";
            this.m_Version = "";
            this.m_Created = DateTime.Now;
            this.m_Path = "";
        }

        public DATA(string Database, string Version, DateTime Created, string Path)
        {
            this.m_Database = Database;
            this.m_Version = Version;
            this.m_Created = Created;
            this.m_Path = Path;
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { this.m_Database };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("DATA_Delete", myParams, myValues);
        }

        public string Delete(string Database)
        {
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { Database };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("DATA_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string Database)
        {
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { Database };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DATA_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string Database)
        {
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { Database };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DATA_Delete", myParams, myValues);
        }

        public bool Exist(string Database)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { Database };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DATA_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string Database)
        {
            string str = "";
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { Database };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DATA_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Database = Convert.ToString(reader["Database"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Path = Convert.ToString(reader["Path"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string Database)
        {
            string str = "";
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { Database };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "DATA_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Database = Convert.ToString(reader["Database"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Path = Convert.ToString(reader["Path"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string Database)
        {
            string str = "";
            string[] myParams = new string[] { "@Database" };
            object[] myValues = new object[] { Database };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "DATA_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Database = Convert.ToString(reader["Database"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Path = Convert.ToString(reader["Path"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("DATA_GetList");
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { this.m_Database, this.m_Version, this.m_Created, this.m_Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("DATA_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { this.m_Database, this.m_Version, this.m_Created, this.m_Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DATA_Insert", myParams, myValues);
        }

        public string Insert(string Database, string Version, DateTime Created, string Path)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { Database, Version, Created, Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("DATA_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string Database, string Version, DateTime Created, string Path)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { Database, Version, Created, Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DATA_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string Database, string Version, DateTime Created, string Path)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { Database, Version, Created, Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DATA_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("DATA", "DATAID", "");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { this.m_Database, this.m_Version, this.m_Created, this.m_Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("DATA_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { this.m_Database, this.m_Version, this.m_Created, this.m_Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DATA_Update", myParams, myValues);
        }

        public string Update(string Database, string Version, DateTime Created, string Path)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { Database, Version, Created, Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("DATA_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string Database, string Version, DateTime Created, string Path)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { Database, Version, Created, Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DATA_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string Database, string Version, DateTime Created, string Path)
        {
            string[] myParams = new string[] { "@Database", "@Version", "@Created", "@Path" };
            object[] myValues = new object[] { Database, Version, Created, Path };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DATA_Update", myParams, myValues);
        }

        public DateTime Created
        {
            get
            {
                return this.m_Created;
            }
            set
            {
                this.m_Created = value;
            }
        }

        public string Database
        {
            get
            {
                return this.m_Database;
            }
            set
            {
                this.m_Database = value;
            }
        }

        public string Path
        {
            get
            {
                return this.m_Path;
            }
            set
            {
                this.m_Path = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class DATA";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        public string Version
        {
            get
            {
                return this.m_Version;
            }
            set
            {
                this.m_Version = value;
            }
        }
    }
}

